<script setup lang="ts">
import { themesStore } from '@/stores/modules/theme'
import { Breadcrumb, Collapsed, FullScreen, Theme, Refresh, UserInfo } from '../../components'

defineProps({
  width: {
    type: Number,
    default: 0,
  },
})

const theme = themesStore()
const { getTopNavIsClose: isClose } = storeToRefs(theme)

const isShow = ref(false)
if (!isClose.value) {
  isShow.value = true
}
let timer = null
const handMouseover = () => {
  if (!isClose.value) return
  if (timer) {
    clearTimeout(timer)
  }
  if (isShow.value) return
  isShow.value = true
}
const handMouseout = () => {
  if (!isClose.value) return
  if (!isShow.value) return
  timer = setTimeout(() => {
    isShow.value = false
  }, 500)
}
</script>

<template>
  <div class="navBar">
    <div
      class="nav"
      :class="{ 'nav-open': isShow }"
      @mouseover="handMouseover"
      @mouseleave="handMouseout"
    >
      <div class="nav-top">
        <div class="nav-main">
          <div class="nav-left">
            <Collapsed />
            <template v-if="width >= 900">
              <Breadcrumb />
            </template>
          </div>
          <div class="nav-right">
            <FullScreen />
            <Theme />
            <Refresh />
            <UserInfo />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.navBar {
  .nav {
    position: relative;
    min-height: 20px;
    transition: all 0.25s;
    .more {
      position: absolute;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      width: 80px;
      height: 20px;
      background: #f2f2f2;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 0 0 10px 10px;
      cursor: pointer;
      opacity: 1;
      transition: all 0.2s;
    }
    .nav-top {
      height: 0px;
      overflow: hidden;
      transition: all 0.25s;
    }
    &-main {
      overflow: hidden;
      padding: 0 20px;
      height: 60px;
      background: var(--yang-menu-navtop-bg-color);
      color: var(--yang-menu-navtop-text-color);
      box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    &-left {
      display: flex;
      align-items: center;
    }
    &-right {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }

    &-open {
      .nav-top {
        height: 60px;
      }
      .more {
        opacity: 0;
      }
    }
  }
}
</style>
